-- global_damage
-- create by panyl
-- 道具：  致命伤害

return {
    apply = function(source, target, classId, value)
        -- 对显性怪物固定伤害
        -- 收集当前层所有未死亡的显性怪物给与伤害

        local ret = {};

        for pos = 1, GRID_SIZE do
            repeat

                local grid = DungeonM.getGridByPos(pos);
                local monster = grid.monster;

                if  not grid:isOpened() or
                    not grid:isMonster() or
                    not monster or
                    monster:isDead() then
                    break;
                end

                if monster ~= target then
                    table.insert(ret, monster);
                end

                -- 传入攻击者信息
                local assailantInfo = {
                    ["property_id"] = classId,
                };

                -- 修正伤害值
                local fixValue = PropertyM.fixPropertyDamage(source, monster, classId, value);

                if ItemM.query(classId, "apply") == "damage_and_drop" then
                    -- 会掉落道具
                    CombatM.doDamage(source, monster, fixValue, 0, true, { assailantInfo = assailantInfo, });
                else
                    CombatM.doDamage(source, monster, fixValue, 0, false, { assailantInfo = assailantInfo, });
                end

            until true;
        end

        -- 抛出使用道具攻击事件
        EventMgr.fire(event.PROPERTY_ATTACK, { ["classId"] = classId, ["target"] = target, ["source"] = source, ["moreTarget"] = ret });
    end,
};
